package com.example.caoben_back.utils;

import com.example.caoben_back.entity.po.User;

import jakarta.servlet.http.HttpServletRequest;

public class TokenUtil {
    
    /**
     * 从request中获取用户信息
     * @param request HTTP请求
     * @return 用户对象
     */
    public static User getUserFromRequest(HttpServletRequest request) {
        return (User) request.getAttribute("user");
    }
    
    /**
     * 从request中获取用户ID
     * @param request HTTP请求
     * @return 用户ID
     */
    public static Integer getUserIdFromRequest(HttpServletRequest request) {
        User user = getUserFromRequest(request);
        return user != null ? user.getUserId() : null;
    }
}